﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace SilverlightSphereControl
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            _sphereControls = new List<SphereControl>(){
                ImageSphereControl,
                VideoSphereControl,
                RectangleSphereControl,
                SphereSphereControl,
            };
        }

        private List<SphereControl> _sphereControls;

        private void RandomButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeDispersalpatterns(DispersalPattern.Random);
        }

        private void CheckeredButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeDispersalpatterns(DispersalPattern.Checkered);
        }

        private void ColumnsButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeDispersalpatterns(DispersalPattern.Column);
        }

        private void VerticalButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeDispersalpatterns(DispersalPattern.VerticalCarousel);
        }

        private void HorizontalButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeDispersalpatterns(DispersalPattern.HorizontalCarousel);
        }

        private void RowsButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeDispersalpatterns(DispersalPattern.Row);
        }

        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            ImageSphereControl.Children.Add(new Image() { Width = 50, Height = 50, Source = new BitmapImage(new Uri("Media/F1_add.jpg", UriKind.Relative)) });
            VideoSphereControl.Children.Add(new MediaElement() { Width = 100, Height = 100, Source = new Uri(@"/Media/f355_nsxs0_48kbps.wmv", UriKind.Relative) });
            RectangleSphereControl.Children.Add(new Rectangle() { Width = 50, Height = 50, Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.Blue) });
        }

        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            ImageSphereControl.Children.Remove(ImageSphereControl.Children[0]);
            VideoSphereControl.Children.Remove(VideoSphereControl.Children[0]);
            RectangleSphereControl.Children.Remove(RectangleSphereControl.Children[0]);
        }

        private void SphereControl_TargetChanging(object sender, EventArgs e)
        {
            RotationStatusRectangle.Fill = new SolidColorBrush(Colors.Yellow);
        }

        private void SphereControl_TargetChanged(object sender, EventArgs e)
        {
            RotationStatusRectangle.Fill = new SolidColorBrush(Colors.Green);
        }

        private void ChangeDispersalpatterns(DispersalPattern pattern)
        {
            foreach (SphereControl sphere in _sphereControls)
            {
                sphere.DispersalPattern = pattern;
            }
        }
     

    }
}
